﻿Imports System.IO

Public Class ctrAcessoBD

#Region "Variáveis"

    Private objAcesso As New PersistenciaPadrao.AcessoBD()
    Private objSeguranca As New PersistenciaPadrao.Uteis

#End Region

#Region "Métodos"

    Public Function montaStringConexao(ByVal sSenha As String,
                                       ByVal sBanco As String,
                                       ByVal sServidor As String,
                                       ByVal sUsuario As String) As String

        Return Me.objAcesso.montaStringConexao(sSenha, sBanco, sServidor, sUsuario)

    End Function

    Public Function testarConexao(ByVal sStringConexao As String) As Boolean

        Return Me.objAcesso.testarConexao(sStringConexao)

    End Function

    Public Sub salvarArquivoConexao(ByVal sSenha As String,
                                    ByVal sBanco As String,
                                    ByVal sServidor As String,
                                    ByVal sUsuario As String)

        Dim sCaminhoArquivo As String
        Dim sArquivoConexao As StreamWriter
        Dim sStringconexaoBD As String

        Try

            sStringconexaoBD = Me.montaStringConexao(sSenha, sBanco, sServidor, sUsuario)

            sCaminhoArquivo = PersistenciaPadrao.AcessoBD.sCaminhoAplicacao & "\SQL.con"

            If IO.File.Exists(sCaminhoArquivo) Then
                IO.File.Delete(sCaminhoArquivo)
            End If

            sArquivoConexao = New IO.StreamWriter(sCaminhoArquivo, IO.FileMode.Create)

            sArquivoConexao.WriteLine(Me.objSeguranca.criptografar(sStringconexaoBD))
            sArquivoConexao.Close()

        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try

    End Sub

#End Region

End Class
